﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 图书管理系统
{
    public partial class user3 : Form
    {
        public user3()
        {
            InitializeComponent();
            table();
        }

        private void user3_Load(object sender, EventArgs e)
        {

        }
        public void table()
        {
            dataGridView1.Rows.Clear();//清空表格中已有数据
            SQLconnect sqlconnect = new SQLconnect();
            string sql = $"select [no],[id],[name],[author],[press],[datetime] from t_lend where [uid]={Data.UID}";
            IDataReader dc = sqlconnect.read(sql);
            while (dc.Read())
            {

                dataGridView1.Rows.Add(dc[0].ToString(), dc[1].ToString(), dc[2].ToString(), dc[3].ToString(), dc[4].ToString(), dc[5].ToString());
            }
            dc.Close();
            sqlconnect.SQLclose();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string no = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            string id = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            string sql = $"delete from t_lend where [no]={no};update t_book set number=number+1 where id='{id}'";
            SQLconnect sqlconnect = new SQLconnect();
            if (sqlconnect.Execute(sql) > 1)
            {
                MessageBox.Show("归还成功");
                table();
            }
            else
            {
                MessageBox.Show("归还失败，请稍后重试");
            }
        }
    }
}
